package com.hzlh.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


public class MD5 {
	public static String encode(String source) {
		String encode_str=null;
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(source.getBytes());
			byte b[] = md.digest();

			int i=0;
			StringBuffer buf = new StringBuffer("");
			for (int offset = 0; offset < b.length; offset++) {
				i = b[offset];
				if (i < 0) {
					i += 256;
				}
				if (i < 16) {
					buf.append("0");
				}
				buf.append(Integer.toHexString(i));
			}
			encode_str=buf.toString();
		} catch (NoSuchAlgorithmException e) {
		}
		return encode_str;
	}
	
	public static void main(String[] args) {
		System.out.println(encode("123456"));
	}

}
